package com.ruoyi.system.controller;


import com.ruoyi.system.domain.CourtStatistic;
import com.ruoyi.system.service.CourtStatisticService;
import com.ruoyi.reservationserver.utils.Result;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 球场数据统计表
(CourtStatistic)表控制层
 *
 * @author makejava
 * @since 2023-07-04 16:21:47
 */
@RestController
@RequestMapping("courtStatistic")
public class CourtStatisticController {

    /**
     * 服务对象
     */

    @Resource
    private CourtStatisticService courtStatisticService;

    @GetMapping("totalNum")
    public Result totalUser(){

        return Result.success(courtStatisticService.getTotalSum());
    }




    /**
     * @param courtStatistic
     * @param pageRequest
     * @return
     * @Author: CGY
     * @Updator: CGY
     * @Date 2023-09-13 14:04
     */
    @GetMapping
    public ResponseEntity<Page<CourtStatistic>> queryByPage(CourtStatistic courtStatistic, PageRequest pageRequest) {
        return ResponseEntity.ok(this.courtStatisticService.queryByPage(courtStatistic, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<CourtStatistic> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.courtStatisticService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param courtStatistic 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<CourtStatistic> add(CourtStatistic courtStatistic) {
        return ResponseEntity.ok(this.courtStatisticService.insert(courtStatistic));
    }

    /**
     * 编辑数据
     *
     * @param courtStatistic 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<CourtStatistic> edit(CourtStatistic courtStatistic) {
        return ResponseEntity.ok(this.courtStatisticService.update(courtStatistic));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.courtStatisticService.deleteById(id));
    }

}

